<html>
<body>

<?php 
 $url=$_POST["name"];
 $shopCode='';
 $item_id='';
 
 //get shopCode from URL
 //if(preg_match("/(http:\/\/)*[^\/]*\/([^\/]*)/i",$url,$matches)){
 	if(preg_match("/http:\/\/.*?\/(.+)\//i",$url,$matches)){
 	$shopCode = $matches[2];
 	//echo $shopCode;
 	}else{
 		echo "get shopCode error";
 		}
 		
 $ch = curl_init();
 
 curl_setopt($ch, CURLOPT_URL, $url);
 
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

 curl_setopt($ch, CURLOPT_HTTPAUTH,CURLAUTH_NTLM);

 curl_setopt($ch, CURLOPT_PROXY, 'http://proxysv.intra.rakuten.co.jp:80');

 curl_setopt($ch, CURLOPT_PROXYPORT, '80');

 curl_setopt($ch, CURLOPT_PROXYUSERPWD, "ar-chengjun.zhang:Nr0097xv");
 
 $data = curl_exec($ch);

//curl_close($ch);
	
if(preg_match("/<input value=\"([0-9]+)\" type=\"\w*\" name=\"item_id\">/iUs",$data,$matches1)){

$item_id = $matches1[1];
}else{
	echo "no Item_id error";
} 

$itemCode=$shopCode.':'.$item_id;
//echo $itemCode;

//get imformation by itemcode search API
$url = 'http://api.rakuten.co.jp/rws/3.0/json?';
$developerId='d8907e15edf85f0f302dfbb08ee8d5e9';
$affiliateId='0eb14fc9.51366477.0eb14fca.155c4d47';
$operation='ItemCodeSearch';
$version='2010-08-05';

$url = $url.'developerId='.$developerId.'&affiliateId='.$affiliateId.'&operation='.$operation.'&version='.$version.'&itemCode='.$itemCode;

 curl_setopt($ch, CURLOPT_URL, $url);
 
 $content = curl_exec($ch);
//echo $content;

$Items_Array = json_decode($content,true);
curl_close($ch);

//echo $Item_object;

$item_arry= $Items_Array["Body"]["ItemCodeSearch"]["Items"]["Item"][0];
//echo $item_arry["genreId"];

$mediumImageUrl=$item_arry["mediumImageUrl"];
$affiliateUrl=$item_arry["affiliateUrl"];
$itemPrice=$item_arry["itemPrice"];



//print("<IMG SRC=\"".$item_smallImageUrl."\" alt=\"aaa\">");
?><br />

<!--<?php echo $mediumImageUrl;?>
<br/>

<?php echo $affiliateUrl;?>
<br/>

<?php echo $itemPrice;?>
<br/>

<?php echo $itemCode;?>
<br/>-->

<?php echo form_open('welcome/items_insert');?>

<?php echo form_hidden('affiliate_url',$affiliateUrl);?>
<?php echo form_hidden('item_price',$itemPrice);?>
<?php echo form_hidden('user_id','1234567');?>
<?php echo form_hidden('creat_time',date('Y-m-d H:i:s'));?>
<?php echo form_hidden('item_code',$itemCode);?>
<?php echo form_hidden('img_url',$mediumImageUrl);?>

<IMG SRC="<?php print $mediumImageUrl ?>" alt="aaa" name="img_url">
<p><textarea name="description" row='3'></textarea></p>

<p><input type="submit" value="submit"/></p>

</form>


</body>
</html>